using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for SiteUrls
/// </summary>
namespace SqlWebAdmin.CSharp
{
    public class SiteUrls
    {
        public SiteUrls()
        {
        }

        public static String AdminHome()
        {
            return "~/Administration/default.aspx";
        }

        public static string MaintenaceHome()
        {
            return "~/Maintenance/default.aspx";
        }

        public static string ServerHealth()
        {
            return "~/ServerHealth/default.aspx";
        }
		public static string Credentials()
		{
			return "~/credentials.aspx";
		}
        public static string CreateDatabase()
        {
            return "~/Administration/CreateDatabase.aspx";
        }

        public static string CreateTable(string databaseName)
        {
            return String.Format("~/Administration/CreateTable.aspx?{0}={1}",
                QueryStringKeys.Database, HttpUtility.UrlDecode(databaseName));
        }

        public static string DatabaseProperties(string databaseName)
        {
            return String.Format("~/Administration/DatabaseProperties.aspx?{0}={1}",
                QueryStringKeys.Database, HttpUtility.UrlDecode(databaseName));
        }

        public static string Databases()
        {
            return "~/Administration/Databases.aspx";
        }

        public static string DeleteColumn(string databaseName, string tableName, string schemaName)
        {
            return String.Format("~/DeleteColumn.aspx?{0}={1}&{2}={3}&{4}={5}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.Table, HttpUtility.UrlEncode(tableName),
                QueryStringKeys.Schema, HttpUtility.UrlEncode(schemaName));
        }

        public static string DeleteDatabase(string databaseName)
        {
            return string.Format("~/DeleteDatabase.aspx?{0}={1}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName));
        }

        public static string DeleteStoredProcedure(string databaseName, string storedProcedureName)
        {
            return String.Format("~/DeleteStoredProcedure.aspx?{0}={1}&{2}={3}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.StoredProcedure, HttpUtility.UrlEncode(storedProcedureName));
        }

        public static string DeleteTable(string databaseName, string tableName, string schemaName)
        {
            return String.Format("~/DeleteTable.aspx?{0}={1}&{2}={3}&{4}={5}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.Table, HttpUtility.UrlEncode(tableName),
                QueryStringKeys.Schema, HttpUtility.UrlEncode(schemaName));
        }

        public static string EditColumn(string databaseName, string tableName, string columnName, string schemaName)
        {
            return String.Format("~/EditColumn.aspx?{0}={1}&{2}={3}&{4}={5}&{6}={7}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.Table, HttpUtility.UrlEncode(tableName),
                QueryStringKeys.Column, HttpUtility.UrlEncode(columnName),
                QueryStringKeys.Schema, HttpUtility.UrlEncode(schemaName));
        }

        public static string Error(int errorNumber)
        {
            return String.Format("~/Error.aspx?error={0}", errorNumber.ToString());
        }

        public static string Home()
        {
            return String.Format("~/Default.aspx");
        }
        public static string Home(string errorMessageKey)
        {
            return String.Format("~/Default.aspx?error={0}", errorMessageKey);
        }

        public static string Logout()
        {
            return "~/Logout.aspx";
        }

        public static string StoredProcedures(string databaseName)
        {
            return String.Format("~/Administration/StoredProcedures.aspx?{0}={1}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName));
        }

        public static string StoredProcedure(string databaseName, string storedProcedureName, string schemaName)
        {
            return String.Format("~/Administration/EditStoredProcedure.aspx?{0}={1}&{2}={3}&{4}={5}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.StoredProcedure, HttpUtility.UrlEncode(storedProcedureName),
                QueryStringKeys.Schema, HttpUtility.UrlEncode(schemaName));
        }

        public static string Tables(string databaseName)
        {
            return String.Format("~/Administration/Tables.aspx?{0}={1}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName));
        }

        public static string Table(string databaseName, string tableName, string schemaName)
        {
            return String.Format("~/Administration/EditStoredProcedure.aspx?{0}={1}&{2}={3}&{4}={5}",
                QueryStringKeys.Database, HttpUtility.UrlEncode(databaseName),
                QueryStringKeys.Table, HttpUtility.UrlEncode(tableName),
                QueryStringKeys.Schema, HttpUtility.UrlEncode(schemaName));
        }

        public static string Generic(string url, System.Collections.Specialized.NameValueCollection queryStringPairs)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            string seperator = url.Contains("?") ? "&" : "?";
            foreach (System.Collections.DictionaryEntry entry in queryStringPairs)
            {
                sb.AppendFormat("{0}{1}={2}", seperator, entry.Key, entry.Value);
                seperator = "&";
            }
            return url + sb.ToString();
        }
    }
}